package com.cci.kangdao.crmapi;

import com.cci.kangdao.dao.model.SSRepairT;
import com.cci.kangdao.dao.model.ServiceStationT;
import com.cci.kangdao.utilTool.LocalTimeUtil;
import com.cci.kangdao.utilTool.MapUtil;
import net.sf.json.JSONArray;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CRMRequestMapToAppMapUtils {


    /**
     * 1、创建工单参数转化-DCEC
     *
     * @param @param  map
     * @param @return 参数
     * @return Map<String, Object>    返回类型
     * @throws
     * @Title: workOrderFieldCreate
     * @Description: TODO(这里用一句话描述这个方法的作用)
     */
    public static Map<String, Object> workOrderFieldCreate(Map<String, Object> map) {

		Map<String,Object> appMap = new HashMap<String, Object>();
		String OrderSource = map.get("orderSource").toString();
		if (OrderSource.equals("1")) {// 用户在线报修未指派服务站
			appMap.put("OrderSource", "0");
		} else if(OrderSource.equals("2")){//服务站crm报修
			appMap.put("OrderSource", "3");
		} else if (OrderSource.equals("3")) {//400报修
			appMap.put("OrderSource", "2");
		}else if (OrderSource.equals("4")) {//服务站APP报修
			appMap.put("OrderSource", "1");
		}else if (OrderSource.equals("5")) {// 工单改派
			appMap.put("OrderSource", "4");
		}else if(OrderSource.equals("6")){// 用户在线报修未指派服务站
			appMap.put("OrderSource", "5");
		}
		if (map.containsKey("CRMNo")) {
			appMap.put("OrderNoCrm",map.get("CRMNo"));
		}
		if (map.containsKey("APPOrderNo")) {
			appMap.put("APPOrderNo", map.get("APPOrderNo"));
		}
		appMap.put("ESN", map.get("ESN"));
		appMap.put("VIN", map.get("equipmentNo"));
		appMap.put("CustomerName", map.get("customerName"));
		appMap.put("CustomerPhone", map.get("customerPhone"));
		appMap.put("LocLon", map.get("faultLat"));// 因为文档写反了
		appMap.put("LocLat", map.get("faultLon"));
		appMap.put("Location", map.get("faultLocation"));
		appMap.put("IsOutside", map.get("needGoOut"));
		//工单生成时间
		appMap.put("CreateTime", map.get("orderCreatTime"));
		appMap.put("CustomerComplaint",map.get("faultDesc"));

		// 非工单转换
		appMap.put("BusinessNo", map.get("stationNo"));
		appMap.put("CompanyNo",map.get("serviceChannel"));


		// TODO >>服务子类型转换
		appMap.put("ServiceSubtype", MapUtils.getString(map, "serviceSubtype"));
		appMap.put("UnifiedRepairNo", MapUtils.getString(map, "unifiedRepairNo",""));

		// 索赔性质(1.质量索赔;2.商务活动3.善意担保)
		appMap.put("NatureClaim", MapUtils.getString(map,"natureClaim"));
		// 救急方式(1.派人，2.派车，3.新机检查，4.非发动机原因)
		appMap.put("EmergencyMode", MapUtils.getString(map,"emergencyMode"));


		/**
		 * DCEC amt工单需求 2022-12-26
		 * 新增3个参数
		 * 【变速箱序列号】，amtNo
		 * 【保修性质】，warrantyNature
		 * 【故障发生时间】，faultHappenTime
		 * todo 判断三个参数是否存在为 null 和 不传的情况 ？
		 * @warn  sf传入参数首字母小写， 工单创建首字母是大写
		 *
		 */
		appMap.put("AmtNo", MapUtils.getString(map, "amtNo"));
		appMap.put("WarrantyNature", MapUtils.getString(map, "warrantyNature"));
		appMap.put("FaultHappenTime", MapUtils.getString(map, "faultHappenTime"));
		/**
		 * 2023-1-18 根据保修性质字段判断该工单是哪个工单
		 */
		if(appMap.get("WarrantyNature").equals("发动机保修") ){
			appMap.put("OrderType",2);
		}else {
			appMap.put("OrderType",3);
		}

		return appMap;

	}
	/**
	 * 1、创建工单参数转化-DCEC
	 * @Title: workOrderFieldCreate
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param map
	 * @param @return    参数
	 * @return Map<String,Object>    返回类型
	 * @throws
	 */
	public static Map<String,Object> workOrderFieldCreateFromXCEC(Map<String,Object> map){

		Map<String,Object> appMap = new HashMap<String, Object>();
		String OrderSource = map.get("orderSource").toString();
		appMap.put("OrderSource", OrderSource);
		if (map.containsKey("CRMNo")) {
			appMap.put("OrderNoCrm",map.get("CRMNo"));
		}
		if (map.containsKey("APPOrderNo")) {
			appMap.put("APPOrderNo", map.get("APPOrderNo"));
		}
		appMap.put("ESN", map.get("ESN"));
		appMap.put("VIN", map.get("equipmentNo"));
		appMap.put("CustomerName", map.get("customerName"));
		appMap.put("CustomerPhone", map.get("customerPhone"));
		appMap.put("LocLon", map.get("faultLat"));// 因为文档写反了
		appMap.put("LocLat", map.get("faultLon"));
		appMap.put("Location", map.get("faultLocation"));
		appMap.put("IsOutside", map.get("needGoOut"));
		// 工单类别
		appMap.put("OrderType", map.get("orderType"));
		//工单生成时间
		appMap.put("CreateTime", map.get("orderCreatTime"));
		appMap.put("CustomerComplaint", map.get("faultDesc"));

		// 非工单转换
		appMap.put("BusinessNo", map.get("stationNo"));
		appMap.put("CompanyNo", map.get("serviceChannel"));

		// TODO >>服务子类型转换
		appMap.put("ServiceSubtype", MapUtils.getString(map, "serviceSubtype"));
		appMap.put("UnifiedRepairNo", MapUtils.getString(map, "unifiedRepairNo",""));
        appMap.put("salesServiceType", MapUtils.getString(map, "salesServiceType"));

		//是否是大工匠工单
		appMap.put("IsTechSupport", MapUtils.getBoolean(map, "isTechnicalSupport", false) ? 1 : 0);
		//技术支持内容
		appMap.put("TechSupportContent", MapUtils.getString(map, "technicalSupportNote"));
		return appMap;

	}
	/**
	 * 0、更新工单状态参数转化-CCI
	 * @Title: workOrderFieldCreate
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param map
	 * @param @return    参数
	 * @return Map<String,Object>    返回类型
	 * @throws
	 */
	public static Map<String,Object> workOrderFieldUpdateFromDBU(Map<String,Object> orderMap,Map<String,Object> crmMap){


		if (crmMap.containsKey("CRMNo")) {
			orderMap.put("OrderNoCrm",crmMap.get("CRMNo"));
		}

		//工单更新时间
		orderMap.put("UpdateTime", crmMap.get("systemTime"));
		orderMap.put("Updator", -1);
		orderMap.put("CompanyNo",crmMap.get("company"));
		orderMap.put("OperatorPhone",crmMap.get("operatorPhone"));
		orderMap.put("IsClosed",crmMap.get("isClosed"));
		orderMap.put("stations",crmMap.get("stations"));
		orderMap.put("rejectedReason", crmMap.get("rejectedReason"));
		//工单类型
		orderMap.put("scenarioStatus",crmMap.get("scenarioStatus"));
		// 区域指派表数据
		orderMap.put("DoMaindId",crmMap.get("domainId"));
		orderMap.put("OrderId",orderMap.get("ID"));
		orderMap.put("ID",orderMap.get("ID"));
		orderMap.put("DBEngineerName",crmMap.get("dbEngineerName"));
		orderMap.put("DBEngineerPhone",crmMap.get("dbEngineerMobile"));
        if (StringUtils.isNotBlank(MapUtil.getMapValue(crmMap, "BookkeepingType"))) {
            orderMap.put("BookkeepingType", crmMap.get("BookkeepingType"));
        }
		if (crmMap.get("scenarioStatus").toString().equals("5")
				|| crmMap.get("scenarioStatus").toString().equals("8")
				|| crmMap.get("scenarioStatus").toString().equals("12")){
			// 指派区域
			orderMap.put("IsHaveDBEngineer",1);
		}else
		{
			// 不指派区域
			orderMap.put("IsHaveDBEngineer",0);
			orderMap.put("AssignStationTime",crmMap.get("systemTime"));
		}
		orderMap.put("SellType",crmMap.get("sellType"));
		return orderMap;

	}

	/**
	 * 1、创建工单参数转化-CCI
	 * @Title: workOrderFieldCreate
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param map
	 * @param @return    参数
	 * @return Map<String,Object>    返回类型
	 * @throws
	 */
	public static Map<String,Object> workOrderFieldCreateFromDBU(Map<String,Object> map){

		Map<String,Object> appMap = new HashMap<String, Object>();
		appMap.put("OrderSource", 2);
		if (map.containsKey("CRMNo")) {
			appMap.put("OrderNoCrm",map.get("CRMNo"));
		}
		if (map.containsKey("APPOrderNo")) {
			appMap.put("APPOrderNo", map.get("APPOrderNo"));
		}
		appMap.put("ESN", map.get("ESN"));
		appMap.put("SMN", MapUtils.getString(map,"SMN"));
		appMap.put("VIN", map.get("equipmentNo"));
		appMap.put("MarketType", map.get("marketTypes"));
		appMap.put("Application", map.get("applications"));
		appMap.put("WarrantyStartDate", map.get("warrantyStartDate"));
		appMap.put("OEMName", MapUtils.getString(map,"vehicleCompany",""));
		appMap.put("manufactor", map.get("manufactor"));
		appMap.put("stations",map.get("stations"));

		appMap.put("CustomerName", map.get("customerName"));
		appMap.put("CustomerPhone", map.get("customerPhone"));
		appMap.put("LocLat", map.get("faultLat"));// 文档已经更正
		appMap.put("LocLon", map.get("faultLon"));
		appMap.put("Location", map.get("faultLocation"));
		appMap.put("LocProvince", map.get("faultProvince"));
		appMap.put("LocCity", map.get("faultCity"));
		//工单生成时间
		appMap.put("CreateTime", map.get("creatTime"));
		appMap.put("Creator", -1);
		appMap.put("CustomerComplaint",map.get("faultDesc"));

		// 非工单转换
		appMap.put("CustomerType", map.get("customerType"));
		appMap.put("CustomerCompanyName", map.get("customerCompany"));
		appMap.put("CustomerCompanyProvince", map.get("customerCompanyProvince"));
		appMap.put("CustomerCompanyCity", map.get("customerCompanyCity"));
		appMap.put("WorkHours", map.get("workHours"));
		appMap.put("WorkMileages", map.get("workMileages"));
		appMap.put("CompanyNo",map.get("serviceChannel"));

		// 区域指派表数据
		appMap.put("DBEngineerName",map.get("dbEngineerName"));
		appMap.put("DBEngineerPhone",map.get("dbEngineerMobile"));

		// 服务子类型 2.8.0需求
		appMap.put("ServiceSubtype", MapUtils.getString(map, "serviceSubtype"));
		appMap.put("UnifiedRepairNo", MapUtils.getString(map, "unifiedRepairNo",""));

		// 客户标准化输入 2.9.0需求
		appMap.put("FaultCodes", MapUtils.getString(map, "faultCodes"));
		appMap.put("SymptomName", MapUtils.getString(map, "symptomName"));

        // sprint36   添加【保内】，【保外】，【业务支持】
        appMap.put("BookkeepingType", MapUtils.getString(map, "BookkeepingType"));
		//DBU工单】【安卓】【IOS】【BE】创建工单-增加售时售前售后
		appMap.put("SellType", MapUtils.getString(map, "sellType"));

		List<Map<String, Object>> serviceStationList = JSONArray.fromObject(appMap.get("stations").toString());
		if (serviceStationList != null){
			if (serviceStationList.size() == 1){
				if (serviceStationList.get(0).get("isRecommend").toString().equals("0")){
					appMap.put("IsHaveDBEngineer",0);
				}else
				{
					appMap.put("IsHaveDBEngineer",1);
				}

			}else
			{
				appMap.put("IsHaveDBEngineer",1);
			}
		}else
		{
			appMap.put("IsHaveDBEngineer",1);
		}
		// 服务商列表
		appMap.put("ServiceStationList",serviceStationList);
		appMap.put("SystemTime",map.get("creatTime"));
		appMap.put("Flag",0);
		return appMap;

	}

	/**
	 * 2、同步服务站数据参数转化
	 * @Title: syncServiceStationInfosFromCRM
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param map
	 * @param @param serviceStationn
	 * @param @return    参数
	 * @return Map<String,Object>    返回类型
	 * @throws
	 */
	public static Map<String,Object> syncServiceStationInfosFromCRM(Map<String,Object> map,ServiceStationT serviceStationn){

		Map<String,Object> appMap = new HashMap<String, Object>();
		if (serviceStationn == null) {//此时APP系统没有服务站数据
			appMap.put("ssid", "");
			appMap.put("CompanyNo", map.get("company"));
			appMap.put("BusinessNo", map.get("stationNo"));
			appMap.put("StationName", map.get("stationName"));
			appMap.put("Abbreviation", map.get("shortName"));
			appMap.put("Province", map.get("province"));
			appMap.put("City", map.get("city"));
			appMap.put("Area", map.get("area"));
			appMap.put("PositionLat", map.get("positionLat"));
			appMap.put("PositionLon", map.get("positionLon"));
			appMap.put("Address", map.get("address"));

			appMap.put("Contact", map.get("contact"));
			appMap.put("Telephone", map.get("telephone"));
			appMap.put("Phone", map.get("phone"));
			appMap.put("BuildDate", map.get("authTime"));
			appMap.put("Conferend", map.get("conferend"));


			appMap.put("Fax", "");
			appMap.put("Zipcode", "");
			appMap.put("BuildDate", "");
			appMap.put("CompanyType","0");
			appMap.put("LegalPerson", "");
			appMap.put("LegalMobile", "");
			appMap.put("TaxCard", "");
			appMap.put("TaxAddress", "");
			appMap.put("BillType", "0");

			appMap.put("BillName", "");
			appMap.put("BillMobile", "");
			appMap.put("BankName", "");
			appMap.put("BankAccount", "");
			appMap.put("BusinessScope", "");
			appMap.put("BusinessAdd", "");
			appMap.put("Systime", LocalTimeUtil.getRealCurrentTime());

			appMap.put("VehicleType", map.get("vehicleType"));// （SSHasVehicleType）
			appMap.put("EngineTypes", map.get("engineTypes"));//（SSHasEngineType） #####发动机机型，需要根据typeName反查EngineType表
			appMap.put("SSAuth", map.get("repairScope")); // （SSRepire_T）
			appMap.put("SSType", map.get("stationType"));
			appMap.put("AuthTime", map.get("authTime"));
			appMap.put("HotlineTel", map.get("hotLine"));
			appMap.put("Tel", map.get("telephone"));
			if (map.get("serviceType").toString().equals("3")) {//（SSHasServiceType） 如果3（包内、保外） 可以
				appMap.put("ServiceType", "1,2");//
			}else {
				appMap.put("ServiceType", map.get("serviceType"));
			}
			appMap.put("ShowAbb", map.get("shortName"));
			appMap.put("AuthChannel","JV");
			/**
			 * 未确定字段
			 */
			appMap.put("VehicleCompanies", map.get("vehicleCompanies"));// （SSHasCompany） 由于没有OEM厂家列表，暂时不处理
			appMap.put("Remark", map.get("remark"));
			appMap.put("Flag", 0);

		}else { // 此时APP系统有服务站数据
			appMap.put("ssid", String.valueOf(serviceStationn.getId()));
			appMap.put("id", String.valueOf(serviceStationn.getId()));
			appMap.put("CompanyNo", map.get("company"));
			appMap.put("BusinessNo", map.get("stationNo"));
			if (map.get("shortName").toString().length() > 0) {
				appMap.put("Abbreviation", map.get("shortName"));
			}
			if (map.get("stationName").toString().length() > 0) {
				appMap.put("StationName", map.get("stationName"));
			}
			if (map.get("province").toString().length() > 0) {
				appMap.put("Province", map.get("province"));
			}
			if (map.get("city").toString().length() > 0) {
				appMap.put("City", map.get("city"));
			}
			if (map.get("area").toString().length() > 0) {
				appMap.put("Area", map.get("area"));
			}
			if (serviceStationn.getPositionLat().length() < 0 && map.get("positionLat").toString().length() > 0) {
				appMap.put("PositionLat", map.get("positionLat"));
			}
			if (serviceStationn.getPositionLon().length() < 0 && map.get("positionLon").toString().length() > 0) {
				appMap.put("PositionLon", map.get("positionLon"));
			}
			if (map.get("address").toString().length() > 0) {
				appMap.put("Address", map.get("address"));
			}

			if (map.get("contact").toString().length() > 0) {
				appMap.put("Contact", map.get("contact"));
			}
			if (map.get("hotLine").toString().length() > 0) {
				appMap.put("Telephone", map.get("hotLine"));
			}
			if (map.get("phone").toString().length() > 0) {
				appMap.put("Phone", map.get("phone"));
			}
			if (serviceStationn.getBuilddate().length() < 0 && map.get("authTime").toString().length() > 0) {
				appMap.put("BuildDate", map.get("authTime"));
			}

			appMap.put("VehicleType", map.get("vehicleType"));// （SSHasVehicleType）
			appMap.put("EngineTypes", map.get("engineTypes"));//（SSHasEngineType） #####发动机机型，需要根据typeName反查EngineType表
			appMap.put("SSAuth", map.get("repairScope")); // （SSRepire_T）
			appMap.put("SSType", map.get("stationType"));
			appMap.put("AuthTime", map.get("authTime"));
			appMap.put("HotlineTel", map.get("hotLine"));
			appMap.put("Conferend", map.get("conferend"));
			appMap.put("Tel", map.get("telephone"));
			if (map.get("serviceType").toString().equals("3")) {//（SSHasServiceType） 如果3（包内、保外） 可以
				appMap.put("ServiceType", "1,2");//
			}else {
				appMap.put("ServiceType", map.get("serviceType"));
			}
			/**
			 * 未确定字段
			 */
			appMap.put("VehicleCompanies", map.get("vehicleCompanies"));// （SSHasCompany） 由于没有OEM厂家列表，暂时不处理
			appMap.put("Remark", map.get("remark"));
			appMap.put("Flag", 0);
		}

		return appMap;

	}

	/**
	 * 根据CRM 服务站数据更新SSRepair表数据
	 * @Title: syncSSRepairInfosFromCRM
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param map
	 * @param @param repair
	 * @param @return
	 * @return Map<String,Object>
	 * @throws
	 */
	public static Map<String,Object> syncSSRepairInfosFromCRM(Map<String,Object> map,SSRepairT repair){
		Map<String,Object> appMap = new HashMap<String, Object>();
		appMap.put("SSRepairId",repair.getId());
		appMap.put("ServiceStationID",repair.getServicestationid());
		appMap.put("CompanyID",repair.getCompanyid());
		if (map.containsKey("shortName")
				&& map.get("shortName") != null
				&& map.get("shortName").toString().length() > 0) {
			if (!repair.getShowabb().equals(map.get("shortName").toString())) {
				appMap.put("ShowAbb", map.get("shortName"));
			}
		}

		if (map.containsKey("repairScope")
				&& map.get("repairScope") != null
				&& map.get("repairScope").toString().length() > 0) {
			if (!repair.getSsauth().equals(map.get("repairScope").toString())) {
				appMap.put("SSAuth", map.get("repairScope")); // （SSRepire_T）
			}
		}
		if (map.containsKey("stationType")
				&& map.get("stationType") != null
				&& map.get("stationType").toString().length() > 0) {
			if (!repair.getSstype().toString().equals(map.get("stationType").toString())) {
				appMap.put("SSType", map.get("stationType"));
			}
		}
		if (map.containsKey("hotLine")
				&& map.get("hotLine") != null
				&& map.get("hotLine").toString().length() > 0) {
			if (!repair.getHotlinetel().equals(map.get("hotLine").toString())) {
				appMap.put("HotlineTel", map.get("hotLine"));
			}
		}
		return appMap;
	}

    /**
	 * 同步区域管辖信息，convert crmMap to appMap
	 * @Title: toPositionInfoMap
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param crmMap
	 * @param @return
	 * @return HashMap<String,Object>
	 * @throws
	 */
	public static Map<String, Object> toPositionInfoMap(Map<String,Object> crmMap){
		if (!crmMap.containsKey("requstStatus")
				|| !crmMap.containsKey("positionNo")
				||!crmMap.containsKey("level")) {
			return null;
		}

		Map<String,Object> appMap = new HashMap<>();
		appMap.put("CrmPostNo", crmMap.get("positionNo"));
		if (MapUtils.getIntValue(crmMap,"CompanyID",-1) == 1){ // DBU
			appMap.put("Level", 1);
		}else
		{
			appMap.put("Level", MapUtils.getIntValue(crmMap,"level",0));
		}
		appMap.put("Status", crmMap.get("requstStatus"));
		appMap.put("positionId", -1);
		appMap.put("Creator",crmMap.get("CompanyID"));
		if (crmMap.containsKey("position")) {
			appMap.put("CrmPositionName", crmMap.get("position"));
		}
		appMap.put("AppPositionName", CRMServiceConst.CRMAPPROVEROLE_INAPP_ONE);

		if (crmMap.get("requstStatus").toString().equals("1")) {// 增加
			appMap.put("CreateTime", LocalTimeUtil.getRealCurrentTime());
			appMap.put("Updator", appMap.get("Creator"));
			appMap.put("UpdateTime", appMap.get("CreateTime"));
			appMap.put("Flag", 0);
		}else if (crmMap.get("requstStatus").toString().equals("3")) {// 修改
			appMap.put("Updator", crmMap.get("CompanyID"));
			appMap.put("UpdateTime", LocalTimeUtil.getRealCurrentTime());
			appMap.put("Flag", 0);
		}else if (crmMap.get("requstStatus").toString().equals("2")) {// 删除
			appMap.put("Deleter", crmMap.get("CompanyID"));
			appMap.put("DeleteTime", LocalTimeUtil.getRealCurrentTime());
			appMap.put("Flag", -1);
		}

		return appMap;
	}

	public static Map<String, Object> toXCECPositionInfoMap(Map<String,Object> crmMap){
		if (!crmMap.containsKey("positionNo")
				||!crmMap.containsKey("level")) {
			return null;
		}

		Map<String,Object> appMap = new HashMap<String, Object>();
		appMap.put("CrmPostNo", crmMap.get("positionNo"));
		if (MapUtils.getIntValue(crmMap,"CompanyID",-1) == 1){ // DBU
			appMap.put("Level", 1);
		}else
		{
			appMap.put("Level", MapUtils.getIntValue(crmMap,"level",0));
		}
		appMap.put("Status", 1);
		appMap.put("positionId", -1);
		appMap.put("Creator",crmMap.get("CompanyID"));
		if (crmMap.containsKey("position")) {
			appMap.put("CrmPositionName", crmMap.get("position"));
		}
		appMap.put("AppPositionName", CRMServiceConst.CRMAPPROVEROLE_INAPP_ONE);

		appMap.put("CreateTime", LocalTimeUtil.getRealCurrentTime());
		appMap.put("Updator", appMap.get("Creator"));
		appMap.put("UpdateTime", appMap.get("CreateTime"));
		appMap.put("Flag", 0);

		return appMap;
	}

    public static Map<String, Object> toDBUPositionInfoMap(Map<String,Object> dbuCrmMap){
        if (!dbuCrmMap.containsKey("requstStatus") || !dbuCrmMap.containsKey("domainName") ||!dbuCrmMap.containsKey("domainId")) {
            return null;
        }
        Map<String,Object> appDBUMap = new HashMap<String, Object>();
        appDBUMap.put("CrmPostNo", dbuCrmMap.get("domainId"));
        appDBUMap.put("Level", 1);
        appDBUMap.put("Status", dbuCrmMap.get("requstStatus"));
        appDBUMap.put("CrmId", dbuCrmMap.get("crmId"));
        appDBUMap.put("positionId", -1);
        appDBUMap.put("Creator",dbuCrmMap.get("CompanyID"));
        if (dbuCrmMap.containsKey("domainName")) {
            appDBUMap.put("CrmPositionName", dbuCrmMap.get("domainName"));
        }
        appDBUMap.put("AppPositionName", CRMServiceConst.CRMAPPROVEROLE_INAPP_DBU);

        if (dbuCrmMap.get("requstStatus").toString().equals("1")) {// 增加
            appDBUMap.put("CreateTime", LocalTimeUtil.getRealCurrentTime());
			appDBUMap.put("Updator", appDBUMap.get("Creator"));
			appDBUMap.put("UpdateTime", appDBUMap.get("CreateTime"));
            appDBUMap.put("Flag", 0);
        }else if (dbuCrmMap.get("requstStatus").toString().equals("3")) {// 修改
            appDBUMap.put("Updator", dbuCrmMap.get("CompanyID"));
            appDBUMap.put("UpdateTime", LocalTimeUtil.getRealCurrentTime());
            appDBUMap.put("Flag", 0);
        }else if (dbuCrmMap.get("requstStatus").toString().equals("2")) {// 删除
            appDBUMap.put("Deleter", dbuCrmMap.get("CompanyID"));
            appDBUMap.put("DeleteTime", LocalTimeUtil.getRealCurrentTime());
            appDBUMap.put("Flag", -1);
        }

        return appDBUMap;
    }
	/**
	 * 同步区域管辖人员信息，convert crmMap to appMap
	 * @Title: toPositionContactInfoMap
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param crmContactMap
	 * @param @return
	 * @return Map<String,Object>
	 * @throws
	 */
    public static Map<String, Object> toPositionContactInfoMap(Map<String,Object> crmContactMap){
        if (!crmContactMap.containsKey("requstStatus") || !crmContactMap.containsKey("phone")) {
            return null;
        }
        Map<String,Object> appContactMap = new HashMap<String, Object>();
        appContactMap.put("UserPhone", crmContactMap.get("phone"));
        appContactMap.put("PositionID", crmContactMap.get("positionId"));
        appContactMap.put("UserID", crmContactMap.get("userId"));
        appContactMap.put("Status", crmContactMap.get("requstStatus"));
        appContactMap.put("Creator", crmContactMap.get("Creator"));

        if (crmContactMap.get("requstStatus").toString().equals("1")) {// 增加
            appContactMap.put("CreateTime", LocalTimeUtil.getRealCurrentTime());
            appContactMap.put("Updator", appContactMap.get("Creator"));
            appContactMap.put("UpdateTime", appContactMap.get("CreateTime"));
            appContactMap.put("Flag", 0);
            appContactMap.put("positionUserID", -1);
        } else if (crmContactMap.get("requstStatus").toString().equals("3")) {// 修改
            appContactMap.put("Updator", appContactMap.get("Creator"));
            appContactMap.put("UpdateTime", LocalTimeUtil.getRealCurrentTime());
            appContactMap.put("Flag", 0);
        } else if (crmContactMap.get("requstStatus").toString().equals("2")) {// 删除
            appContactMap.put("Deleter", appContactMap.get("Creator"));
            appContactMap.put("DeleteTime", LocalTimeUtil.getRealCurrentTime());
            appContactMap.put("Flag", -1);
        }
        // 此时没有查出PositionID的值
        if (appContactMap.get("PositionID").toString().equals("-1")) {
            appContactMap.put("Flag", -1);
        }

        return appContactMap;
    }


    /**
     * 同步区域管辖人员信息，convert crmMap to appMap
     *
     * @param @param  crmContactMap
     * @param @return
     * @return Map<String, Object>
     * @throws
     * @Title: toPositionContactInfoMap
     * @Description: TODO(这里用一句话描述这个方法的作用)
     */
    public static Map<String, Object> toPositionContactInfo(Map<String, Object> crmContactMap) {
        if (!crmContactMap.containsKey("requstStatus") || !crmContactMap.containsKey("phone")) {
            return null;
        }
        Map<String, Object> appContactMap = new HashMap<String, Object>();
        appContactMap.put("UserPhone", crmContactMap.get("phone"));
        appContactMap.put("SMN", MapUtils.getString(crmContactMap, "SMN", ""));
        appContactMap.put("Province", crmContactMap.get("Province"));
        appContactMap.put("City", crmContactMap.get("City"));
        appContactMap.put("Marketing", MapUtils.getString(crmContactMap, "Marketing", ""));
        appContactMap.put("PositionID", crmContactMap.get("positionId"));
        appContactMap.put("Status", crmContactMap.get("requstStatus"));
        appContactMap.put("ContactName", crmContactMap.get("contactName"));
        appContactMap.put("CrmId", crmContactMap.get("crmId"));
        appContactMap.put("Creator", crmContactMap.get("CompanyID"));


        if (crmContactMap.get("requstStatus").toString().equals("1")) {// 增加
            appContactMap.put("CreateTime", LocalTimeUtil.getRealCurrentTime());
            appContactMap.put("Updator", appContactMap.get("Creator"));
            appContactMap.put("UpdateTime", appContactMap.get("CreateTime"));
            appContactMap.put("Flag", 0);
            appContactMap.put("positionUserID", -1);
        }else if (crmContactMap.get("requstStatus").toString().equals("3")) {// 修改
            appContactMap.put("Updator", appContactMap.get("Creator"));
            appContactMap.put("UpdateTime", LocalTimeUtil.getRealCurrentTime());
            appContactMap.put("Flag", 0);
        }else if (crmContactMap.get("requstStatus").toString().equals("2")) {// 删除
            appContactMap.put("Deleter", appContactMap.get("Creator"));
            appContactMap.put("DeleteTime", LocalTimeUtil.getRealCurrentTime());
            appContactMap.put("Flag", -1);
        }
        // 此时没有查出PositionID的值
        if (appContactMap.get("PositionID").toString().equals("-1")){
            appContactMap.put("Flag", -1);
        }

        return appContactMap;
    }
	/**
	 * 同步区域管辖人员信息，convert crmMap to appMap
	 * @Title: toPositionContactInfoMap
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param crmContactMap
	 * @param @return
	 * @return Map<String,Object>
	 * @throws
	 */
	public static Map<String, Object> toXCECPositionContactInfoMap(Map<String,Object> crmContactMap){
		if (!crmContactMap.containsKey("phone")) {
			return null;
		}
		Map<String,Object> appContactMap = new HashMap<String, Object>();
		appContactMap.put("UserPhone", crmContactMap.get("phone"));
		appContactMap.put("PositionID", crmContactMap.get("positionId"));
		appContactMap.put("UserID", crmContactMap.get("userId"));
		appContactMap.put("Status", 1);
		appContactMap.put("Creator", crmContactMap.get("Creator"));

		appContactMap.put("CreateTime", LocalTimeUtil.getRealCurrentTime());
		appContactMap.put("Updator", appContactMap.get("Creator"));
		appContactMap.put("UpdateTime", appContactMap.get("CreateTime"));
		appContactMap.put("Flag", 0);
		appContactMap.put("positionUserID", -1);
		// 此时没有查出PositionID的值
		if (appContactMap.get("PositionID").toString().equals("-1")){
			appContactMap.put("Flag", -1);
		}

		return appContactMap;
	}

	/**
	 * 转化SSRepairT为Map
	 * @Title: toPositionUserServiceMap
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param repairT
	 * @param @return
	 * @return Map<String,Object>
	 * @throws
	 */
	public static Map<String, Object> toPositionUserServiceMap(SSRepairT repairT,long postUserId,String requestStatus,long creator){

		Map<String,Object> appContactServiceMap = new HashMap<String, Object>();
		appContactServiceMap.put("ServiceStationID", repairT.getServicestationid());
		appContactServiceMap.put("ServiceStationNo", repairT.getBusinessno());
		appContactServiceMap.put("CompanyID", repairT.getCompanyid());
		appContactServiceMap.put("PositionUserID", postUserId);
		appContactServiceMap.put("Status", requestStatus);
		appContactServiceMap.put("Creator", creator);

		if (requestStatus.equals("1")) {// 增加

			appContactServiceMap.put("CreateTime", LocalTimeUtil.getRealCurrentTime());
			appContactServiceMap.put("Flag", 0);
			appContactServiceMap.put("Updator", creator);
			appContactServiceMap.put("UpdateTime", LocalTimeUtil.getRealCurrentTime());
			appContactServiceMap.put("positionUserServiceStationId", "");
		}else if (requestStatus.equals("3")) {// 修改
			appContactServiceMap.put("Updator", creator);
			appContactServiceMap.put("UpdateTime", LocalTimeUtil.getRealCurrentTime());
			appContactServiceMap.put("Flag", 0);
		}else if (requestStatus.equals("2")) {// 删除
			appContactServiceMap.put("Deleter", creator);
			appContactServiceMap.put("DeleteTime", LocalTimeUtil.getRealCurrentTime());
			appContactServiceMap.put("Flag", -1);
		}

		// 此时没有查出PositionUserID的值
		if (appContactServiceMap.get("PositionUserID").toString().equals("-1")){
			appContactServiceMap.put("Flag", -1);
		}

		return appContactServiceMap;
	}

	public static Map<String, Object> toXCECPositionUserServiceMap(SSRepairT repairT,long postUserId,String requestStatus,long creator){

		Map<String,Object> appContactServiceMap = new HashMap<String, Object>();
		appContactServiceMap.put("ServiceStationID", repairT.getServicestationid());
		appContactServiceMap.put("ServiceStationNo", repairT.getBusinessno());
		appContactServiceMap.put("CompanyID", repairT.getCompanyid());
		appContactServiceMap.put("PositionUserID", postUserId);
		appContactServiceMap.put("Status", requestStatus);
		appContactServiceMap.put("Creator", creator);
		appContactServiceMap.put("CreateTime", LocalTimeUtil.getRealCurrentTime());
		appContactServiceMap.put("Flag", 0);
		appContactServiceMap.put("positionUserServiceStationId", "");

		// 此时没有查出PositionUserID的值
		if (appContactServiceMap.get("PositionUserID").toString().equals("-1")){
			appContactServiceMap.put("Flag", -1);
		}

		return appContactServiceMap;
	}

	/**
	 * 1、创建工单参数转化-CCI
	 * @Title: workOrderFieldCreate
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param map
	 * @param @return    参数
	 * @return Map<String,Object>    返回类型
	 * @throws
	 */
	public static Map<String,Object> newWorkOrderFieldCreateFromDBU(Map<String,Object> oldAppOrder,Map<String,Object> crmOrder){

		Map<String,Object> appMap = new HashMap<String, Object>();
		if (crmOrder.containsKey("CRMNo")) {
			appMap.put("OrderNoCrm",crmOrder.get("CRMNo"));
		}
		appMap.put("OrderChannel", oldAppOrder.get("OrderChannel"));
		appMap.put("OrderSource", oldAppOrder.get("OrderSource"));
		appMap.put("ESN", crmOrder.get("ESN"));
		appMap.put("EngineMsgId", MapUtils.getIntValue(oldAppOrder,"EngineMsgId",0));
		appMap.put("OEMName", MapUtils.getString(oldAppOrder,"OEMName",""));
		appMap.put("VIN", MapUtils.getString(oldAppOrder,"VIN",""));
		appMap.put("MarketType", MapUtils.getString(oldAppOrder,"MarketType",""));
		appMap.put("Application", MapUtils.getString(oldAppOrder,"Application",""));
		appMap.put("WarrantyStartDate", MapUtils.getString(oldAppOrder,"WarrantyStartDate",""));
		appMap.put("vehicleCompany", MapUtils.getString(oldAppOrder,"vehicleCompany",""));
		appMap.put("manufactor", MapUtils.getString(oldAppOrder,"manufactor",""));

		appMap.put("CustomerName", MapUtils.getString(oldAppOrder,"CustomerName",""));
		appMap.put("CustomerPhone", MapUtils.getString(oldAppOrder,"CustomerPhone",""));
		appMap.put("LocLat", MapUtils.getDoubleValue(oldAppOrder,"LocLat",0.00));// 文档已经更正
		appMap.put("LocLon", MapUtils.getDoubleValue(oldAppOrder,"LocLon",0.00));
		appMap.put("Location", MapUtils.getString(oldAppOrder,"Location",""));
		appMap.put("LocProvince", MapUtils.getString(oldAppOrder,"LocProvince",""));
		appMap.put("LocCity", MapUtils.getString(oldAppOrder,"LocCity",""));
		//工单生成时间
		appMap.put("CreateTime", MapUtils.getString(oldAppOrder,"CreateTime",""));
		appMap.put("Creator", -1);
		appMap.put("CustomerComplaint",MapUtils.getString(oldAppOrder,"CustomerComplaint",""));

		// 非工单转换
		appMap.put("CustomerType", MapUtils.getString(oldAppOrder,"CustomerType",""));
		appMap.put("CustomerCompanyName", MapUtils.getString(oldAppOrder,"CustomerCompanyName",""));
		appMap.put("CustomerCompanyProvince", MapUtils.getString(oldAppOrder,"CustomerCompanyProvince",""));
		appMap.put("CustomerCompanyCity", MapUtils.getString(oldAppOrder,"CustomerCompanyCity",""));
		appMap.put("WorkHours", MapUtils.getString(oldAppOrder,"WorkHours",""));
		appMap.put("WorkMileages", MapUtils.getString(oldAppOrder,"WorkMileages",""));
		appMap.put("CompanyNo",MapUtils.getString(crmOrder,"company",""));

		// 区域指派表数据
		appMap.put("DBEngineerName",MapUtils.getString(crmOrder,"dbEngineerName",""));
		appMap.put("DBEngineerPhone",MapUtils.getString(crmOrder,"dbEngineerMobile",""));
		appMap.put("SystemTime",MapUtils.getString(crmOrder,"systemTime",""));
		appMap.put("Flag",0);
		appMap.put("scenarioStatus",crmOrder.get("scenarioStatus"));
        appMap.put("BookkeepingType", crmOrder.get("BookkeepingType"));

		return appMap;

	}
}
